#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Import UUID-package to generate random-filenames, if prog called without filename-parameter
import uuid

# Import own JSONFuse package for main functionality
import JSONFuse

# ----------

if __name__ == '__main__':
	# Set FUSE-version
	JSONFuse.fuse.fuse_python_api=JSONFuse.fuse.FUSE_PYTHON_API_VERSION

	# Set global prog name variable
	PROG_NAME="MyJSONInADir"

	# Initializing FUSE-Object
	jsonFuse=JSONFuse.JSONFuse(version="%prog, "+JSONFuse.fuse.__version__, usage=PROG_NAME+", "+JSONFuse.fuse.Fuse.fusage, dash_s_do='setsingle')

	# Adding MyJSONInADir-specific parameters
	optGroup=jsonFuse.parser.add_option_group(PROG_NAME+" options")
	optGroup.add_option("--json-filename", help="Defines the JSON-File, if no file is given a temporary name will be assigned.", action="store", type="string", metavar="filename", dest="filename", default=None)
	optGroup.add_option("--json-verbose", help="Set verbosity, used with fuse-mount-options -d or -f.", action="store_true", dest="verbose", default=False)
	optGroup.add_option("--json-indentation", help="Defines with how many spaces the json-file will be indented with.", action="store", type="int", metavar="indentation", dest="indentation", default=None)
	optGroup.add_option("--json-encoding", help="Defines which encoding has to be used for the json-file, default latin1.", action="store", type="string", metavar="encoding", dest="encoding", default="latin1")
	optGroup.add_option("--json-no-translate-boolean", help="Defines that strings will NOT be checked if they are boolean-valued, like \"True\" -> True.", action="store_true", dest="translateBoolean", default=False)
	optGroup.add_option("--json-no-translate-numbers", help="Defines that strings will NOT be checked if they are number-valued, like \"123\" -> 123 or \"123.45\" -> 123.45", action="store_true", dest="translateNumbers", default=False)
	optGroup.add_option("--json-no-translate-none", help="Defines that strings will NOT be checked if they are None-valued, like \"None\" -> None", action="store_true", dest="translateNone", default=False)

	# Parse parameters
	options, args=jsonFuse.parser.parse_args()

	# Transfer Parameters
	jsonFuse.setVerbosity(options.verbose)
	jsonFuse.setIndentation(options.indentation)
	jsonFuse.setEncoding(options.encoding)
	jsonFuse.setTranslateBoolean(not options.translateBoolean)
	jsonFuse.setTranslateNumbers(not options.translateNumbers)
	jsonFuse.setTranslateNone(not options.translateNone)

	# Setting json-filename
	if options.filename==None: options.filename="%s_%s" % (PROG_NAME, uuid.uuid4())
	if options.verbose: print "* Using given json-filename: ", options.filename
	jsonFuse.setFilename(options.filename)

	# Start FUSE
	jsonFuse.main()
# End if		
